package org.oschina.api.upload.service;

import java.util.List;
import org.oschina.Message;
import org.oschina.Module;
import org.oschina.ResultUtil;
import org.oschina.api.BaseService;
import org.oschina.api.upload.dao.UploadConfigDAO;
import org.oschina.api.upload.model.UploadConfig;
import org.oschina.api.upload.vo.UploadConfigVo;
import org.oschina.bean.Result;
import org.oschina.security.annotation.Require;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UploadConfigService extends BaseService {
	
	@Autowired
	private UploadConfigDAO uploadConfigDAO;

	/**
	 * 返回
	 * @return
	 */
	@Require(authorization=Module.MODULE_19)
	public List<UploadConfigVo> findVo()
	{
		return _findVo();
	}
	
	/**
	 * 更新
	 * @param uploadConfig
	 * @return
	 */
	@Require(authorization=Module.MODULE_19)
	public Result update(UploadConfig uploadConfig)
	{
		if(_update(uploadConfig)==0)
			return ResultUtil.getFailure(Message.ERROR_DATA_ERROR);
		
		return ResultUtil.getSuccess(uploadConfig);
	}
	
	/**
	 * 根据ID返回
	 * @param id
	 * @return
	 */
	public UploadConfigVo _findVoById(int id)
	{
		return uploadConfigDAO.findVoById(id);
	}
	
	/**
	 * 返回
	 * @return
	 */
	public List<UploadConfigVo> _findVo()
	{
		return uploadConfigDAO.findVo();
	}
	
	/**
	 * 更新
	 * @param uploadConfig
	 * @return
	 */
	private int _update(UploadConfig uploadConfig)
	{
		return uploadConfigDAO.update(uploadConfig);
	}
}